# 未完成，输出格式对
from langchain_openai import ChatOpenAI
from pydantic import BaseModel, Field
from langchain.output_parsers import PydanticOutputParser
from langchain.prompts import PromptTemplate

model = ChatOpenAI(
    temperature=0,
    openai_api_key="sk-rgymzddvnnrgwawnkevkdzlxkxfvhbviqgibbfgpvsyoqtur",
    openai_api_base="https://api.siliconflow.cn/v1",
    model="Qwen/Qwen3-8B"
)


class Joke(BaseModel):
    setup: str = Field(description="")
    punchline: str = Field(description="")


parser = PydanticOutputParser(pydantic_object=Joke)

prompt = PromptTemplate(
    template="回答用户的输入.\n{format_instructions}\n{query}\n",
    input_variables=["query"],
    partial_variables={"format_instructions": parser.get_format_instructions()})

prompt_and_model=prompt | model
out_put = prompt_and_model.invoke({"query": "讲个笑话"})
print(out_put)


